package com.quick.system.listener;

import com.quick.common.constants.Constants;
import com.quick.framework.event.LogEvent;
import com.quick.framework.event.LogoutEvent;
import com.quick.framework.manager.AsyncManager;
import com.quick.system.domain.SysOperateLog;
import com.quick.system.manager.AsyncLogService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 监听
 *
 * @Author: Administrator
 * @Date: 2023/8/30
 */
@Component
public class SystemListener {
    @EventListener
    public void logoutEvent(LogoutEvent logoutEvent) {
        AsyncManager.getInstance().execute(AsyncLogService.recordLoginInfo(logoutEvent.getUserName(), Constants.LOGOUT, "退出成功"));
    }

    @EventListener
    public void logoutEvent(LogEvent logEvent) {
        SysOperateLog sysOperateLog = new SysOperateLog();
        BeanUtils.copyProperties(logEvent.getSysLog(), sysOperateLog);
        sysOperateLog.setOperateTime(new Date());
        AsyncManager.getInstance().execute(AsyncLogService.recordOperateInfo(sysOperateLog));
    }
}
